﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TheOutfield.UmbExt.UniversalMediaPicker.Providers.SlideShare
{
    public class SlideShareProvider : AbstractProvider
    {
        private SlideShareConfigControl _configControl;
        private SlideShareCreateControl _createControl;

        public SlideShareProvider()
        { }

        public SlideShareProvider(string config)
            : base(config)
        { }

        public override string Alias
        {
            get { return "SlideShare"; }
        }

        public override Interfaces.IConfigControl ConfigControl
        {
            get
            {
                if(_configControl == null)
                    _configControl = new SlideShareConfigControl(Config);

                return _configControl;
            }
        }

        public override Interfaces.ICreateControl CreateControl
        {
            get
            {
                if(_createControl == null)
                    _createControl = new SlideShareCreateControl(Config);

                return _createControl;
            }
        }

        public override MediaItem GetMediaItemById(string id)
        {
            var service = new SlideShareService(Config);
            var slideshowId = 0;

            return int.TryParse(id, out slideshowId) ? service.GetSlideshow(slideshowId).ToMediaItem() : null;
        }

        public override IList<MediaItem> GetMediaItems(string parentId)
        {
            var service = new SlideShareService(Config);
            var slideshows = service.GetSlideshows();

            return slideshows.Select(slideshow => slideshow.ToMediaItem()).ToList();
        }
    }
}